﻿Imports DTO
Imports System.Data.SqlClient

Public Class TaiKhoanDAO

    Public Function KiemTraTKDAO(ByVal _tkDTO As TaiKhoanDTO) As Boolean
        Dim sql As String = "select * from TaiKhoan where TenDangNhap = '" & _tkDTO.TenDangNhap.Replace("'", "''") & "'"

        Dim dt As New DataTable()
        dt = DataProvider.LoadSQL(sql)
        If (dt.Rows.Count = 1) Then
            Return True
        Else
            Return False
        End If

    End Function

    Public Function KiemTraTKVaMKDAO(ByVal _tkDTO As TaiKhoanDTO) As Boolean
        Dim sql As String = "select * from TaiKhoan where TenDangNhap = '" & _tkDTO.TenDangNhap.Replace("'", "''") & "' and MatKhau = '" & _tkDTO.MatKhau.Replace("'", "''") & "'"
        Dim dt As New DataTable()
        dt = DataProvider.LoadSQL(sql)
        If (dt.Rows.Count = 1) Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Function GetLoaiTKDAO(ByVal _tkDTO As TaiKhoanDTO) As Integer
        Dim sql As String = "select LoaiTK from TaiKhoan where TenDangNhap = '" & _tkDTO.TenDangNhap.Replace("'", "''") & "'"

        Dim dt As New DataTable()
        dt = DataProvider.LoadSQL(sql)
        Return Integer.Parse(dt.Rows(0)(0).ToString())
    End Function

    '---Thêm/ sửa-----
    Public Sub DoiMKDAO(ByVal _tkDTO As TaiKhoanDTO)
        Dim sql As String = "sp_DoiMK"

        Dim _listPara As New List(Of SqlParameter)

        Dim TenDangNhap As New SqlParameter("@TenDangNhap", SqlDbType.VarChar)
        TenDangNhap.Value = _tkDTO.TenDangNhap
        _listPara.Add(TenDangNhap)

        Dim MatKhau As New SqlParameter("@MatKhau", SqlDbType.VarChar)
        MatKhau.Value = _tkDTO.MatKhau
        _listPara.Add(MatKhau)

        DataProvider.ExcuteQueryProc(sql, _listPara)

    End Sub
End Class
